//
//  InviteInfoCell.m
//  Cat
//
//  Created by 卢仕彤 on 2019/3/15.
//  Copyright © 2019年 lushitong. All rights reserved.
//

#import "InviteInfoCell.h"
#import "InviteModel.h"
#import "FLHeadView.h"

@interface InviteInfoCell()

@property (nonatomic, strong) FLHeadView *headView;
@property (nonatomic, strong) UILabel *nickLabel;
@property (nonatomic, strong) UILabel *fansLabel;
@property (nonatomic, strong) UIButton *chooseButton;
@property (nonatomic, strong) InviteModel *inviteInfomodel;

@end

@implementation InviteInfoCell

- (void)setCellModelData:(id)cellModelData {
    if ([cellModelData isKindOfClass:[InviteModel class]]) {
        InviteModel *model = (InviteModel *)cellModelData;
        self.inviteInfomodel = model;
        [self.headView setImageUrl:[NSURL URLWithString:model.avator] size:CGSizeMake(kQKFitModuleDecimal(40.0), kQKFitModuleDecimal(40.0)) cornerRadius:kQKFitModuleDecimal(20.0)];
        self.nickLabel.text = model.nickName;
        self.fansLabel.text = [NSString stringWithFormat:@"粉丝数：%@",model.fansNum];
    }
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.cellSeparatorStyle = QKUITableViewCellSeparatorStyleSingleLineBottomZero;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self loadSubviews];
    }
    return self;
}

- (void)loadSubviews {
    [self.contentView addSubviews:@[self.headView,self.nickLabel,self.fansLabel,self.chooseButton]];
    
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(CGSizeMake(kQKFitModuleDecimal(40.0), kQKFitModuleDecimal(40.0)));
        make.left.equalTo(self.contentView.mas_left).offset(kQKFitModuleDecimal(16.0));
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    
    [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headView.mas_right).offset(kQKFitModuleDecimal(13.0));
        make.top.equalTo(self.contentView.mas_top).offset(kQKFitModuleDecimal(16.0));
    }];
    
    [self.fansLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickLabel.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-kQKFitModuleDecimal(16.0));
    }];
    
    [self.chooseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.right.equalTo(self.contentView.mas_right).offset(-kQKFitModuleDecimal(25.0));
    }];
}

- (void)chooseInviteButtonAction {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickinVitePeopleInfo:)]) {
        [self.delegate clickinVitePeopleInfo:self.inviteInfomodel];
    }
}

#pragma mark lazy init

- (FLHeadView *)headView {
    if (!_headView) {
        _headView = [[FLHeadView alloc] init];
    }
    return _headView;
}

- (UILabel *)nickLabel {
    if (!_nickLabel) {
        _nickLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:kQKFitModuleDecimal(14.0)] textColor:COLOR_WITH_HEX(0x4C4947)];
    }
    return _nickLabel;
}

- (UILabel *)fansLabel {
    if (!_fansLabel) {
        _fansLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:kQKFitFont(10.0)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
    }
    return _fansLabel;
}

- (UIButton *)chooseButton {
    if (!_chooseButton) {
        _chooseButton = [UIButton buttonWithTitle:@"选择" color:COLOR_WITH_HEX(0xFFC236) font:[UIFont systemFontOfSize:14]];
        [_chooseButton addTarget:self action:@selector(chooseInviteButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _chooseButton;
}
@end
